<!--{template common/header_ajax}-->
<script type="text/javascript" reload="1">
  var selorg={};
  //添加
  selorg.add=function(ctrlid,vals){
    var html='';
    var pregmatch = /^dzz(.+?)/;
    for(var i in vals){
      if(jQuery('#'+ctrlid+'_sl_'+vals[i].orgid).length){
        continue;	
      }
      html+='<button id="'+ctrlid+'_sl_'+vals[i].orgid+'" type="button" class="btn btn-simple btn-outline-primary btn-sm btn-sorg" data-val="'+vals[i].orgid+'">';
      
      if(vals[i].icon){
        if(pregmatch.test(vals[i].icon)){
          html+='<span class="'+vals[i].icon+'"></span>';
        }else{
          html+='<img src="'+vals[i].icon+'" class="img-circle special_avatar_class Topcarousel img-avatar">';
        }
      }
      var iconFirstWord=vals[i].path.match(/<span.+?>.+?<\/span>/i);
      if(iconFirstWord){
        html+=iconFirstWord+vals[i].path.replace(/<span.+?>.+?<\/span>/i,'');
      }else{
        html+=vals[i].path;
      }
      html+='<a href="javascript:;" class="ibtn dzz dzz-close mdi mdi-close-circle lead" title="'+__lang.delete+'" onclick="selorg.remove(\''+ctrlid+'\',this);"></a>';
    }
    jQuery('#'+ctrlid).append(html);
    selorg.set(ctrlid);
  };

  //删除
  selorg.del=function(ctrlid,vals){
    for(var i in vals){
      jQuery('#'+ctrlid+'_sl_'+vals[i]).remove();
    }
    selorg.set(ctrlid);
  };

  //设置输入框的值
  selorg.set=function(ctrlid){
    var val=[];
    jQuery('#'+ctrlid+' button').each(function() {
          val.push(jQuery(this).data('val'));
      });
    jQuery('#sel_'+ctrlid).val(val.join(','));
  };
  //y移除，并且取消机构树中的选择
 selorg.remove=function(ctrlid,obj){
	var unsel_val=jQuery(obj).parent().data('val');
	jQuery(obj).parent().remove();
	selorg.set(ctrlid);
	try{window.frames[ctrlid+'_iframe'].selectorg_remove(unsel_val);}catch(e){}
};
  <!--{if $openarr}-->
  selorg.openarr=$openarr;  
  <!--{/if}-->
</script>
<div class="modal-header">
  <h4 class="modal-title text-truncate">{lang set}</h4>
  <div class="float-end">
    <button type="button" class="modal-fullscreen-btn"><i class="mdi"></i></button>
    <button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
  </div>
</div>
<div class="modal-body">
  <div class="row mb-3">
    <label class="col-sm-2" for="orgname">{lang orgname} <span class="text-danger">*</span></label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="orgname" data-oldname="$org[orgname]" value="$org[orgname]" placeholder="{lang orgname_placeholder}" onchange="set_org_orgname('$org['orgid']',this)">
    </div>
  </div>
  <div class="row mb-3">
    <label class="col-sm-2">Logo</label>
    <div class="col-sm-10">
      <ul class="group-head">
        <li class="head-portrait">$org['avatar']</li>
        <li class="head-file me-2">
            <button type="button" class="btn btn-outline-danger" style="margin-top: 5px;cursor: pointer;"><input type="checkbox" class="headinput-checkbox" name="arr[aid]" value="$value[aid]" checked="checked"  onchange="set_org_logo('$org['orgid']',this.value)">{lang reset}</button>
        </li>
        <li class="head-file">
            <button type="button" class="btn btn-outline-primary" style="margin-top: 5px;cursor: pointer;"><input type="file" style=" cursor: pointer;" onclick="upload_bgphoto(this,true)"> {lang change}</button>
        </li>
      </ul>
    </div>
  </div>
  <div class="row mb-3">
      <label class="col-sm-2" for="arrdesc">{lang org_description}</label>
      <div class="col-sm-10">
        <textarea class="form-control" id="arrdesc" name="arr[desc]" placeholder="{lang org_description_placeholder}" onchange="set_org_desc('$org['orgid']',this.value)">$org[desc]</textarea>
      </div>
  </div>
  <!--{if $folder_available}-->
  <!--原共享目录设置：diron,此处暂时用来控制应用内是否开启共享目录，如网盘群组开关不开启，表示网盘内不显示该目录-->
  <div class="row mb-3">
    <label class="col-sm-2">{lang shared_directory_set}</label>
      <div class="col-sm-10">
      <div class="form-check form-check-inline">
        <input class="form-check-input" type="radio" id="folder_available_1" name="fid" value="1" <!--{if $org[diron]>0}-->checked="checked"<!--{/if}--> onclick="folder_available(1,'$orgid');"  />
        <label class="form-check-label" for="folder_available_1">{lang enable}</label>
      </div>
      <div class="form-check form-check-inline">
        <input class="form-check-input" type="radio" id="folder_available_0" name="fid"  value="0" <!--{if $org[diron]<1}-->checked="checked"<!--{/if}--> onclick="folder_available(0,'$orgid');" />
        <label class="form-check-label" for="folder_available_0">{lang no_enable}</label>
      </div>
      <!--{if $org['forgid']<1}-->
      <small class="form-text">{lang detail_org_explorerapp_enable}</small>
      <!--{else}-->
      <small class="form-text">{lang detail_org_enable}</small>
      <!--{/if}-->
      </div>
  </div>
  <!--{/if}-->
  <!--{if $_G['adminid']==1 || $topmoderator}-->
  <div class="row mb-3">
  <label for="maxspacesize" class="col-sm-2">{lang org_space_assign}</label>
    <div class="col-sm-10">
      <div class="input-group mb-3">
      <input type="text" class="form-control" id="maxspacesize" name="maxspacesize" value="$org['maxspacesize']" onchange="folder_maxspacesize(this,'$orgid')">
      <span class="input-group-text">M</span>
      </div>
      <ul class="form-text">
      <li>{lang org_space_assign_tip}:<span class="text-danger">{eval echo ($allowallotspace == 0) ? lang('no_limit'):formatsize($allowallotspace);}</span>
      </li>{lang org_space_assign_tips}
      </ul>
    </div>
  </div>
  <!--{/if}-->
  <div class="row mb-3">
    <label class="col-sm-2"><!--{if $org[forgid]>0}-->{lang space_use_department}<!--{else}-->{lang space_use_org}<!--{/if}--></label>
    <div class="col-sm-10">
      <div class="progress" style="height: 1rem;">
        <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: {eval echo round(100*($org['usesize']/($org['maxspacesize']?$org['maxspacesize']*1024*1024:($org['usesize']+1024*1024*1024))))}%;min-width: 100px;" aria-valuenow="{eval echo round(100*($org['usesize']/($org['maxspacesize']?$org['maxspacesize']*1024*1024:($org['usesize']+1024*1024*1024))))}" aria-valuemin="0" aria-valuemax="100">{eval echo formatsize($org['usesize'])}/{eval if($org['maxallotspacesize'] == -1) echo formatsize($org['usesize']);else echo ($org['maxallotspacesize'] == 0)?lang('no_limit'):formatsize($org['maxallotspacesize'])}</div>
      </div>
      <ul class="form-text">
        {lang space_use_org_tips}
      </ul>
    </div>
  </div>
  <div class="row mb-3">
  <label class="col-sm-2">{lang position_management}</label>
  <div class="col-sm-10 clearfix jobs">
    <!--{loop $jobs $value}-->
    <div id="job_$value[jobid]" orgid="$value['orgid']" class="job-item-edit float-start pe-2">
      <button onclick="job_show_editor('$value[jobid]','$value['orgid']', this)" class="btn btn-outline-secondary job-name">$value[name]</button>
      <div class="edit hide" style="min-width:250px">
        <div class="input-group">
          <div class="job-edit-control float-start">
            <input type="text" class="form-control" value="$value[name]" onkeyup="if(event.keyCode==13){job_save('$value[jobid]','$value['orgid']');return false;}">
          </div>
          <button class="btn btn-outline-secondary" onclick="job_save('$value[jobid]','$value['orgid']')" data-loading-text="{lang save}" type="button">{lang save}</button>
          <button class="btn btn-outline-danger" onclick="job_del('$value[jobid]','$value['orgid']')" type="button">{lang delete} </button>
        </div>
      </div>
    </div>
    <!--{/loop}-->
    <div class="new-job float-start" style="padding:0 10px;">
      <a href="javascript:;" onclick="job_show_add_editor('$orgid',this)" class="btn btn-outline-primary"> {lang add_position} </a>
      <div class="new-job-control hide input-group" style="min-width:250px">
        <div class="float-start">
          <input type="text" class="new-job-text form-control" onkeyup="if(event.keyCode==13){job_add('$orgid');return false;}" placeholder="{lang position_name}">
        </div>
        <button class="btn btn-outline-secondary" data-loading-text="{lang add}" onclick="job_add('$orgid')" type="button">{lang add} </button>
        <button class="btn btn-outline-secondary" onclick="job_cancel_add_editor('$orgid')" type="button">{lang cancel}</button>
      </div>
    </div>
  </div>

  </div>
  <div class="row mb-3">
    <label class="col-sm-2"><!--{if $org['forgid']<1}-->{lang organization}<!--{else}-->{lang department}<!--{/if}-->{lang administrator}</label>
    <div class="col-sm-10">
      <!--{if $pmoderator}-->
      <div class="dropdown">
        <button class="btn btn-primary dropdown-toggle" type="button" id="orgids_Menu" data-toggle="dropdown" aria-expanded="false">{lang please_select_a_organization_or_department}</button>
        <div id="orgids_dropdown_menu" class="dropdown-menu org-sel-box" role="menu" aria-labelledby="orgids_Menu">
          <iframe name="orgids_iframe" class="org-sel-box-iframe" src="{DZZSCRIPT}?mod=system&op=orgtree&template=1&ctrlid=orgids&multiple=1&range=1&stype=2" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true"></iframe>
        </div>
      </div>
      <!--{/if}-->
      <div id="orgids" class="d-flex flex-wrap">
        <!--{loop $moderators $value}-->
        <button id="orgids_sl_uid_$value['uid']" type="button" class="btn btn-outline-primary btn-sm btn-sorg" data-val="uid_$value['uid']">
          {eval echo avatar_block($value['uid']);} $value[username]
          <!--{if $pmoderator}--><a href="javascript:;" class="ibtn mdi mdi-close-circle lead" title="{lang delete}" onclick="selorg.remove('orgids',this);"></a><!--{/if}-->
        </button>
        <!--{/loop}-->
      </div>
      <input id="sel_orgids" name="orgids" type="hidden" value="$sel"/>
      <ul class="form-text">
        {lang detail_org_administrator}
      </ul>
    </div>
  </div>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-secondary" data-dismiss="modal" aria-label="Close">{lang close}</button>
  <button type="button" class="btn btn-primary" onclick="set_submit();">{lang save}</button>
</div>
<script type="text/javascript" reload="1">
    function set_submit() {
      showmessage('{lang In_the_save}','','3000',0);
      var data = {uids:jQuery('#sel_orgids').val(),orgid:'$orgid'};
      jQuery.post('{MOD_URL}&op=ajax&do=orginfo',data, function (data) {
        if (data['success']) {
          showmessage('{lang org_update_success}','success',3000,1);
          if(orgid == '$orgid') {
            showDetail(orgid);
          }
        }else if(data['error']){
          showmessage(data['error'],'danger',3000,1);
        } else {
          showmessage('{lang save_unsuccess}','danger',3000,1);
        }
      },'json').fail(function (jqXHR, textStatus, errorThrown) {
          showmessage('{lang do_failed}', 'error', 3000, 1);
      });
      return false;
    }
    jQuery(document).on('click','.headinput-checkbox',function(){
        if(jQuery(this).prop("checked")){
            jQuery(this).closest('.head-portrait').siblings('.head-portrait').find('.headinput-checkbox').prop('checked',false).parents('.head-checkbox').removeClass('hover');
            jQuery(this).parents('.head-portrait').find('.head-checkbox').addClass('hover');
        }else{
            jQuery(this).parents('.head-portrait').find('.head-checkbox').removeClass('hover');
        }

    });
	function upload_bgphoto(obj,fact) {
        'use strict';
        jQuery(obj).fileupload({
            url: '{MOD_URL}&op=ajax&do=upload',
            dataType: 'json',
            autoUpload: true,
            maxFileSize: 2000000,// 2 MB
            maxChunkSize: 2000000,//2M
            acceptFileTypes: new RegExp("\.([jpe?g|gif|png])$", 'i'),
            sequentialUploads: true,
            add: function (e, data) {
                data.context = jQuery('<div id="main"></div>');
                if (jQuery('#main div:first').length > 0) jQuery('#main div:first').before(data.context);
                else {
                    jQuery('#main').append(data.context);
                }
                data.process().done(function () {
                    data.submit();
                });
            },
            progress: function (e, data) {
                var index = 0; //data.index,
                var node = jQuery(data.context.children()[index]);
                var progress = parseInt(data.loaded / data.total * 100, 10);
                node.find('.progress-bar').css(
                        'width',
                        progress + '%'
                );
            },
            done: function (e, data) {

                jQuery.each(data.result.files, function (index, file) {
                    if (file.error) {
                        data.context.find('.progress').replaceWith('<span class="text-danger">' + file.error + '</span>');
                    } else {
                    	if(fact){
                    		var imgsexists = false;
                    		jQuery('.headinput-checkbox').each(function(){
                    			var oldaid = jQuery(this).val();
								if(oldaid == file.data.aid){
									jQuery(this).prop('checked',true);
									imgsexists = true;
									showmessage('{lang org_img_uploaded_tip}','success',3000,1);
									return false;
								}
							})
							if(!imgsexists){
								/*jQuery.post('{MOD_URL}&op=ajax&do=getdefaultpic',{aid:file.data.aid},function(data){
									if(data['success']){
										//jQuery('.head-checkbox').removeClass('hover').find('.headinput-checkbox').prop('checked',false);*/
										var html ='<li class="head-portrait">'+'<img src="'+file.data.img+'"><div class="head-checkbox hover">'+
												'<div class="checkbox-custom"> <input type="checkbox" class="headinput-checkbox" name="arr[aid]" value="'+file.data.aid+'" checked="checked" onchange="set_org_logo(\'$org['orgid']\',this.value)" />'+
												' </div> </div> ';
										jQuery('.head-portrait').replaceWith(html);
										set_org_logo('$orgid',file.data.aid);
								/*	}
								},'json')*/
							}
                    	}else{
                    		data.context.data('aid', file.data.aid).find('img').attr('src', file.data.img).end().find('.progress-container').hide();
                            var html = '<div class="col-sm-7 setting-img"><img class="img-rounded" src="'+file.data.img+'"><p class="upload-click">{lang clicktoupload}</p> <input type="file" id="exampleInputFile" onclick="upload_bgphoto(this)" name="files[]"></div>';				
							set_org_bgphoto('$org['orgid']',file.data.aid);
                            jQuery('.setting-img').replaceWith(html);

                    	}
                        
                    }
                });
            }
        })
    };
</script>
<!--{template common/footer_ajax}-->